package com.flea.hclv.controller;

import com.alibaba.fastjson.JSONObject;
import com.flea.hclv.model.entity.HCar;
import com.flea.hclv.model.entity.HCarReserve;
import com.flea.hclv.model.entity.HCarReserveItem;
import com.flea.hclv.service.HCarReserveService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.bean.FleaPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * @program: project
 * @description: 车预定
 * @author: shiliqiang
 * @create: 2019-02-23 14:25
 * @version: 1.0
 */
@Controller
@RequestMapping("/flea/hclv/car/reserve/")
public class HCarReserveController {

    @Autowired
    private HCarReserveService hCarReserveService;

    @RequestMapping("add")
    @ResponseBody
    public ServerResponse<String> add(String model, HttpServletRequest request) throws ParseException {
        ServerResponse<String> response = hCarReserveService.addReserveInfo(model, request);
        return response;
    }
    //组团社 供应商 车队 所有预定成功的车队订单
    @ResponseBody
    @RequestMapping("getCarReserveList")
    public ServerResponse<FleaPage<HCarReserve>> getCarReserveList(HttpServletRequest request,FleaPage<HCarReserve> paging
//                                                                   @RequestParam(value = "reserveStatus",defaultValue = "") String reserveStatus
    ){
        ServerResponse<FleaPage<HCarReserve>> response = hCarReserveService.findCarReserveList(paging,request);
        return response;
    }
    //获取待处理的车队订单（同意或者拒绝）
    @ResponseBody
    @RequestMapping("getUnfinished")
    public ServerResponse<FleaPage<HCarReserve>> getUnfinished(HttpServletRequest request,FleaPage<HCarReserve> paging,
                                                               String model){
        JSONObject jsonObject = JSONObject.parseObject(model);
        String reserveStatus;
        if (jsonObject==null){
            reserveStatus= null;
        }else {
            reserveStatus = jsonObject.getString("reserveStatus");
        }
        ServerResponse<FleaPage<HCarReserve>> response = hCarReserveService.getUnfinishedCarReserveList(paging,request,reserveStatus);
        return response;
    }
    //我创建的车队订单（组团社或者供应商订单创建人）
    @ResponseBody
    @RequestMapping("myCarReserveList")
    public ServerResponse<FleaPage<HCarReserve>> myCarReserveList(HttpServletRequest request,FleaPage<HCarReserve> paging,
//                                                                   @RequestParam(value = "reserveStatus",defaultValue = ""
                                                                  String model){
        JSONObject jsonObject = JSONObject.parseObject(model);
        String reserveStatus;
        if (jsonObject==null){
            reserveStatus= null;
        }else {
            reserveStatus = jsonObject.getString("reserveStatus");
        }
        ServerResponse<FleaPage<HCarReserve>> response = hCarReserveService.findMyCarReserveList(paging,request,reserveStatus);
        return response;
    }
    //指定车
    @ResponseBody
    @RequestMapping("reserveCar")
    public ServerResponse<String> reserveCar(HttpServletRequest request,String model) throws Exception {
        ServerResponse<String> response = hCarReserveService.insertReserveOrderItem(request,model);
        return response;
    }
    //更新订单状态
    @ResponseBody
    @RequestMapping("updateReserveStatus")
    public ServerResponse<String> updateReserveStatus(HttpServletRequest request,String model) throws Exception {
        ServerResponse<String> response = hCarReserveService.updateReserveStatus(request,model);
        return response;
    }

    //获取订单项（根据订单号（预定信息ID）车辆列表）
    @RequestMapping("getReserveCarItem")
    @ResponseBody
    public ServerResponse<FleaPage<HCarReserveItem>> getReserveCarItem(HttpServletRequest request, FleaPage<HCar> paging,
                                                                       String reserveCarId){
        ServerResponse<FleaPage<HCarReserveItem>> response = hCarReserveService.getReserveCarItem(paging,reserveCarId);
        return response;
    }
    //获取符合条件的车
    @RequestMapping("getRequireCars")
    @ResponseBody
    public ServerResponse<FleaPage<HCar>> getRequireCars(HttpServletRequest request, FleaPage<HCar> paging,
                                                            String reserveCarId){
        ServerResponse<FleaPage<HCar>> response = hCarReserveService.getRequireCars(request,paging,reserveCarId);
        return response;
    }

}
